<?php 
$numArr = array('1','2','3','4','5','6','7','8','9','10','11');
if ($ans){
	$numArr = explode(',', $ans['res']);
}
?>
<table id="a5" cellspacing="1" cellpadding="3" style="background: #fff;width:100%">
<thead>
<tr class="com_table_tr2">
    <td class="aslefttd">Order</td>
    <td >Info</td>		    
</tr>
</thead>
<tr id="<?php echo $numArr[0]?>" >
    <td class="aslefttd">NO <span><?php echo $numArr[0]?></span> :</td>
    <td><input type="text" class="input4" id="b_<?php echo $numArr[0]?>"  <?php if ($ans) { echo 'value="'.$ans['answer']['b_'.$numArr[0]].'"';}?>></td>			    
</tr>
<tr id="<?php echo $numArr[1]?>"  class="com_table_tr2">
    <td class="aslefttd">NO <span><?php echo $numArr[1]?></span> :</td>
    <td><input type="text" class="input4" id="b_<?php echo $numArr[1]?>" <?php if ($ans) { echo 'value="'.$ans['answer']['b_'.$numArr[1]].'"';}?>></td>			    
</tr>
<tr id="<?php echo $numArr[2]?>">
    <td class="aslefttd">NO <span><?php echo $numArr[2]?></span> :</td>
    <td><input type="text" class="input4" id="b_<?php echo $numArr[2]?>" <?php if ($ans) { echo 'value="'.$ans['answer']['b_'.$numArr[2]].'"';}?>></td>			    
</tr>
<tr id="<?php echo $numArr[3]?>"  class="com_table_tr2">
    <td class="aslefttd">NO <span><?php echo $numArr[3]?></span> :</td>
    <td><input type="text" class="input4" id="b_<?php echo $numArr[3]?>" <?php if ($ans) { echo 'value="'.$ans['answer']['b_'.$numArr[3]].'"';}?>></td>			    
</tr>
<tr id="<?php echo $numArr[4]?>" >
    <td class="aslefttd">NO <span><?php echo $numArr[4]?></span> :</td>
    <td><input type="text" class="input4" id="b_<?php echo $numArr[4]?>" <?php if ($ans) { echo 'value="'.$ans['answer']['b_'.$numArr[4]].'"';}?>></td>			    
</tr>
<tr id="<?php echo $numArr[5]?>"  class="com_table_tr2">
    <td class="aslefttd">NO <span><?php echo $numArr[5]?></span> :</td>
    <td><input type="text" class="input4" id="b_<?php echo $numArr[5]?>" <?php if ($ans) { echo 'value="'.$ans['answer']['b_'.$numArr[5]].'"';}?>></td>			    
</tr>
<tr id="<?php echo $numArr[6]?>" >
    <td class="aslefttd">NO <span><?php echo $numArr[6]?></span> :</td>
    <td><input type="text" class="input4" id="b_<?php echo $numArr[6]?>" <?php if ($ans) { echo 'value="'.$ans['answer']['b_'.$numArr[6]].'"';}?>></td>			    
</tr>
<tr id="<?php echo $numArr[7]?>"  class="com_table_tr2">
    <td class="aslefttd">NO <span><?php echo $numArr[7]?></span> :</td>
    <td><input type="text" class="input4" id="b_<?php echo $numArr[7]?>" <?php if ($ans) { echo 'value="'.$ans['answer']['b_'.$numArr[7]].'"';}?>></td>			    
</tr>
<tr id="<?php echo $numArr[8]?>" >
    <td class="aslefttd">NO <span><?php echo $numArr[8]?></span> :</td>
    <td><input type="text" class="input4" id="b_<?php echo $numArr[8]?>" <?php if ($ans) { echo 'value="'.$ans['answer']['b_'.$numArr[8]].'"';}?>></td>			    
</tr>
<tr id="<?php echo $numArr[9]?>" class="com_table_tr2" >
    <td class="aslefttd">NO <span><?php echo $numArr[9]?></span> :</td>
    <td><input type="text" class="input4" id="b_<?php echo $numArr[9]?>" <?php if ($ans) { echo 'value="'.$ans['answer']['b_'.$numArr[9]].'"';}?>></td>			    
</tr>
<tr id="<?php echo $numArr[10]?>" >
    <td class="aslefttd">NO <span><?php echo $numArr[10]?></span> :</td>
    <td><input type="text" class="input4" id="b_<?php echo $numArr[10]?>" <?php if ($ans) { echo 'value="'.$ans['answer']['b_'.$numArr[10]].'"';}?>></td>			    
</tr>

</table>
<script type="text/javascript">
<?php if ($ans){
	echo "var fsort = '".$ans['res']."';";
}else {
	echo "var fsort = ''";
}?>

$(document).ready(function() {
    // Initialise the table
    $("#a5").tableDnD({
    	
        onDrop: function(table, row) {
        	
	    	var rows = table.tBodies[0].rows;
	        fsort = "";
	        for (var i=0; i<rows.length; i++) {
	        	if(i==0){
	        	    fsort += rows[i].id;
                }else{
                	fsort += ","+rows[i].id;
                }
	        }
	        //alert(fsort);
        }
    });
    
});
function getAnswer()
{
	var b_1 = $.trim($("#b_1").val());
    var b_2 = $.trim($("#b_2").val());
    var b_3 = $.trim($("#b_3").val());
    var b_4 = $.trim($("#b_4").val());
    var b_5 = $.trim($("#b_5").val());
    var b_6 = $.trim($("#b_6").val());
    var b_7 = $.trim($("#b_7").val());
    var b_8 = $.trim($("#b_8").val());
    var b_9 = $.trim($("#b_9").val());
    var b_10 = $.trim($("#b_10").val());
    var b_11 = $.trim($("#b_11").val());
    if (!fsort){
    	fsort='1,2,3,4,5,6,7,8,9,10,11';
    }
    var tmpobj = {"res":fsort,"answer":{
        "b_1":b_1,
        "b_2":b_2,
        "b_3":b_3,
        "b_4":b_4,
        "b_5":b_5,
        "b_6":b_6,
        "b_7":b_7,
        "b_8":b_8,
        "b_9":b_9,
        "b_10":b_10,
        "b_11":b_11
        }
    };
    return $.toJSON(tmpobj);
}
</script>